#include "../MainWindowPresenter.h"

#include <cstddef>

#include "views/IMainWindowView.h"
#include "models/Repository.h"

// Constructor and destructor.

MainWindowPresenter::MainWindowPresenter(IMainWindowView *view)
	: AbstractPresenter<IMainWindowView>(view)
{
	closeWindow = false;
}

MainWindowPresenter::~MainWindowPresenter()
{
	//
}

// Methods.

void MainWindowPresenter::onAddRepository()
{
	Repository *repository = getView()->showAddRepositoryDialog();
	if (repository == NULL)
	{
		return;
	}

	delete repository;
}

void MainWindowPresenter::onTrayIconClicked()
{
	getView()->toggleVisibility();
}

bool MainWindowPresenter::onClose()
{
	if (closeWindow)
	{
		return false;
	}

	getView()->hideWindow();
	return true;
}

void MainWindowPresenter::onExit()
{
	closeWindow = true;
	getView()->closeWindow();
}
